<?php
/**  
* Makermgr.php
* 바로가기 지원목적으로 검색결과 상단에 메이커를 모으기
*/

class MakerPool extends View
{
   private $showMaker;
	
   public function cleanKeyword($str, $split_word)     
   {
      $str     = explode($split_word, $str);
      $pattern = "/[^A-Za-z0-9]/";
	  $keywords = array();
	  
      foreach($str as $word){
		$word       = trim($word);
		$word       = strip_tags($word);
		$word       = preg_replace($pattern, "", $word);
	    if($word === '')  continue;      	// 공백제거
		$keywords[]      = substr($word, 0, 12);      // 연속 최대글자 제한
      }	
	  return $keywords;
   }     
	
	public function arrangeMaker($arrMaker)
	{
		$arrBlock 	= null;
		$numShowMaker	= $this->get_numShowMaker();	// 한 행에 나타낼 메이커 갯수
		$len 		= count($arrMaker); 
		$lenNull  	= $numShowMaker - ($len%$numShowMaker);	// 메이커가 없는 경우 공백 채우기		
		$lenNull  	= ($lenNull == $numShowMaker) ? 0 : $lenNull;
		
		for($i = 0; $i < $len;) 
		{
		   $arrBlock  .= "<div>";  
		   
		   for($j = 0; $j < $numShowMaker; $j++) 
		   {
			  $arrBlock  .= "<span>$arrMaker[$i]</span>";	
			  $i++;
			  
			  if($i == $len) break;
		   } 
		}
		
		if($lenNull != 0)
		{
			for($k = 0; $k < $lenNull;) 
			{
			  $arrBlock  .= "<span>&nbsp;</span>";	
			  $k++;
			}
		   $arrBlock  .= "</div>";  
		}
		
		$arrMaker = "<section id='makerPool'>$arrBlock</section>";
		return $arrMaker;
	}
	
	public function set_numShowMaker($value)
	{
		$this->showMaker = $value;	
	}
	
	public function get_numShowMaker()
	{
		return $this->showMaker;	
	}
	
	public function sameCompany($company)
	{
		if($this->flagMaker != $company)
		{
			$this->flagMaker = $company;
			$this->flagType  = null;
			return false;
		}
		return true;		
	}
	
	public function sameType($type)
	{
		$str = ($this->flagType  !=  $type) ? "<span class='sType sTypeTitle'> $type </span>" : "<span class='sType'> &nbsp; </span>" ;
		$this->flagType = $type;
		return  $str;
	}
	
	public function get_MoveButton()
	{
	return<<< EOD
	 <a href='#' id='goTop' title='위로 이동'> <small>▲ Go Top</small> </a>  
EOD;
	}
	
}
?>